{extend name="public/base"/}
{block name="body"}
<div class="main-box no-header clearfix">
    <header class="main-box-header clearfix">
        <div class="pull-left">
            <h2>{$meta_title}（{$count}）</h2>
        </div>
        <div class="pull-right">
            <button  class="btn btn-primary " data-toggle="modal" data-target="#myModal">导入商品</button>
            <!--{notempty name="$Think.get.category"}	<button class="btn btn-success list_sort" url="{:url('sort','','')}">排序</button>{/notempty}-->
        </div>
    </header>
    <div class="main-box-body clearfix">
        <div class="row">
          <!-- <div class="col-sm-12 col-md-4 col-lg-2">

              <div class="btn-group" role="group" aria-label="...">
                  <a type="button" class="btn btn-default">全部</a>
                  <a type="button" class="btn btn-default">已上架</a>
                  <a type="button" class="btn btn-default">未上架</a>
              </div>
          </div> -->
          <div class="col-sm-12" style="    margin-bottom: 20px;">
            <div class="btn-group" role="group" aria-label="...">
              {volist name="catlist" id="vo"}
                <a href="{:url('goods/jsps', ['modelid'=> $modelid])}?category={$key}" data-id="{$key}" class=" btncatid btn btn-success" style="display:none;" >{$vo}</a>
              {/volist}
            </div>
          </div>
            <form method="get" id="formselect">

                <div class="col-sm-12 col-md-4 col-lg-2">
                    <input type="text" class="form-control" name="keyword" value="" placeholder="请输入关键字">
                </div>
                <div class="col-sm-12 col-md-4">
                    <button class="btn btn-primary" type="submit">搜索</button>
                </div>
            </form>
        </div>

        <script>
            $(function(){
                $('[name="category"], [name="status"]').change(function(){
                    $('#formselect').submit();
                })
            })
        </script>

        <table class="table table-striped table-hover">
            <thead>
            <tr>
                <th width="30"><input class="checkbox check-all" type="checkbox"></th>
                <th width="60">ID</th>
                <th>商品图片</th>
                <th>标题</th>
                <th>分类</th>
                <th>特色描述</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="list" id="item"}
            <tr>
                <td><input class="ids row-selected" type="checkbox" name="ids[]" value="{$item['id']}"></td>
                <td>{$item['id']}</td>
                <td><img src="{$item['cover_id']|get_cover='path','96x50'}" width="96" height="50" /></td>
                <td>{$item['good_name']} <br /><br />
                    {volist name="$item['goodsrule']" id="vo" }
                    <p>规格：{$vo[rule_name]} 成本：{$vo[rule_price]}元  售价：{$vo[rule_price2]}元  库存：{$vo[stock] >10 ? $vo[stock] : $vo[stock].'<span style="font-size: 16px;color: red;">(库存不足！)</span>'} 重量：{$vo[weight]}/斤 </p>
                    {/volist}
                </td>
                <td>{$item['cat_id']|get_table_field="id","cat_name","goodscat"}</td>
                <td>{$item['good_desc']|msubstr=###,0,10}</td>
                <td>
                    <a href="{:url('updateFieldById', ['id'=>$item['id'], 'field'=>'sort', 'value'=> '0'])}" class="ajax-get">刷新</a>

                    <!--<a href="{:url('editStatus',array('id'=>$item['id'], 'status'=>1))}" class="confirm ajax-get">上架</a>-->
                    <!-- <a href="{:url('del',array('id'=>$item['id']))}" class="confirm ajax-get">移除</a> -->
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
        {$list->render()}
    </div>
</div>
</div>

<!-- Modal -->
<div class="modal fade "  id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">导入商品到{$meta_title}</h4>
            </div>


            <form class="form-horizontal" action="" method="post">

                <div class="col-md-4" >
                    <div class="panel panel-default" >
                        <div class="panel-body" style="  margin-left: 40px;" id="catbox">
                            {volist name="catlist" id="vo"}
                            <div class="checkbox" data-dismiss="getGoodsInfoBycatid" data-catid="{$key}">
                                <input  type="checkbox" class="che-all" name="cats[]" value="{$key}">
                                <span class="cattext"  style="cursor: pointer">{$vo}</span>
                            </div>
                            {/volist}
                        </div>
                    </div>

                </div>


                <div class="col-md-7" >
                    <div class="panel panel-default" >
                        <div class="panel-body" style="  margin-left: 40px; max-height: 300px;    overflow: auto;padding: 20px;"  id="goodsbox">
                            {volist name="catlist" id="ct"}
                                <div class="sggod   goodsin{$key}" style="display: none"  >
                                    {assign name="ke" value="$key"}
                                    {volist name="allList" id="vo"}
                                        {eq name="$vo.cat_id" value="$ke" }
                                        <div class="checkbox">
                                            <input type="checkbox" class="checks" value="{$vo.id}" name="goods[]">
                                            <span >{$vo.good_name}</span>
                                        </div>
                                        {/eq}
                                    {/volist}

                                </div>
                            {/volist}
                        </div>
                    </div>
                </div>
                <div class="modal-footer" style="clear: both;">
                    <button type="submit" class="btn btn-primary submit-btn ajax-post"  target-form="form-horizontal">导入</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    $(function () {
           $('[data-dismiss="getGoodsInfoBycatid"]').click(function () {
               var catid = $(this).attr('data-catid')
                $('.sggod').hide()
               $('.goodsin'+catid).show();

//               var modelid = $(this).attr('data-modelid')
//               var html = '';
//               $.get("{:url('getGoodsInfoBycatid')}", { 'catid': catid, 'modelid' : modelid},
//                   function(data){
//
//
//                       for (var item in data) {
//
//                           html += '<div class="checkbox"><input type="checkbox" value="'+data[item]['id']+'">'+data[item]['good_name']+'</div>'
//                       }
//                       $('#goodsbox').html(html)
//                   });


           })

        $(".che-all").click(function() {
            var val = $(this).val();
            $('.goodsin'+val).find('.checks').prop("checked", this.checked);
        });

           $('#catbox .cattext').eq(0).click()

        var rules = '{$goodsIds}';
        rules=rules.split(',')
        $('form').find('.checks').each(function ($e) {
            var val = $(this).val()
            if($.inArray(val, rules)>-1){
                $(this).prop('checked', true)
            }
        })
        var cats = '{$cats}';
        cats=cats.split(',')

        $('form').find('.che-all').each(function ($e) {
            var val = $(this).val()
            if($.inArray(val, cats)>-1){
                $(this).prop('checked', true)
            }
        })

        $('.btncatid').each(function ($e) {
            var val = $(this).attr('data-id')
            if($.inArray(val, cats)>-1){
                $(this).show();
            }
        })



    })
</script>


{/block}
